/**
 * 工单类订单列表配置
 */
import React from 'react';
import { ElFormProps } from '@/components/el/ElForm';
import {
  AddBlue,
  EditBlue,
  ExportBlack,
  ReloadBlue
} from '@/components/el/ElIcon';
import { Link } from 'react-router-dom';
import {
  ActionButtonProps,
  ElSearchTableColumns
} from '@/components/el/ElSearchTable';
import { statusMap } from '@/utils';

// 搜素条件
const getTableSearchFormItems = (): ElFormProps => ({
  items: [
    {
      title: '订单编号',
      name: 'docNo',
      span: 6,
      formOption: {
        type: '$input',
        props: {
          size: 'small'
        }
      }
    },
    {
      title: '客户',
      name: 'custName',
      span: 6,
      formOption: {
        type: '$input',
        props: {
          placeholder: '请输入客户名称'
        }
      }
    },
    {
      title: '销售公司',
      name: 'ouId',
      span: 6,
      formOption: {
        type: '$mg-select-ou',
        props: {
          placeholder: '请选择销售公司'
        }
      }
    },
    {
      title: '业务员',
      name: 'agentKey',
      span: 6,
      formOption: {
        type: '$input',
        props: {
          placeholder: '请输入姓名或编号'
        }
      }
    },
    {
      title: '工单编号',
      name: 'docNo',
      span: 6,
      formOption: {
        type: '$input',
        props: {
          placeholder: '请输入工单编号'
        }
      }
    },
    {
      title: '订单日期',
      name: 'docTime',
      span: 6,
      formOption: {
        type: '$rangePicker'
      }
    },
    {
      title: '是否有售后部门',
      name: 'buFlag',
      span: 6,
      formOption: {
        type: '$select',
        props: {
          options: [
            { value: '1', label: '是' },
            { value: '0', label: '否' }
          ]
        }
      }
    },
    {
      title: '订单类型',
      name: 'docType',
      span: 6,
      formOption: {
        type: '$udc',
        props: {
          placeholder: '请选择订单类型',
          prefixStr: '/yst-system',
          domain: 'SAL',
          udc: 'WO_TYPE'
        }
      }
    }
  ]
});

// 按钮
const getTableActionButtons = (handleButton): Array<ActionButtonProps> => {
  return [
    {
      text: '导出',
      key: 'export',
      icon: <ExportBlack />,
      hidden: false,
      location: 'left',
      authCode: 'oms-order-workList-export',
      handleClick: (value) => handleButton('export', value)
    }
  ];
};

// 列表页----表格配置列
const getTableColumns = (): Array<ElSearchTableColumns> => {
  return [
    {
      title: '序号',
      width: 45,
      align: 'center',
      dataIndex: 'SN',
      render: (value, record, index) => {
        return index + 1;
      }
    },
    {
      title: '订单编号',
      width: 170,
      dataIndex: 'docNo',
      render: (value, record) => {
        return <Link to={`/order/workOrder/view/${record.id}`}>{value}</Link>;
      }
    },
    {
      title: '销售公司',
      width: 200,
      dataIndex: 'ouName'
    },
    {
      title: '销售组织',
      width: 200,
      dataIndex: 'buName'
    },
    {
      title: '订单类型',
      width: 100,
      align: 'center',
      dataIndex: 'docTypeName',
      render: (value, record) => (
        <span style={{ color: statusMap.get(`SO_STATUS_${record.docStatus}`) }}>
          {value}
        </span>
      )
    },
    {
      title: '工单编号',
      width: 150,
      dataIndex: 'docNo'
    },
    {
      title: '业务员编号',
      width: 200,
      dataIndex: 'agentCode'
    },
    {
      title: '业务员姓名',
      width: 130,
      dataIndex: 'agentName'
    },
    {
      title: '下单渠道',
      width: 110,
      dataIndex: 'soSourceName'
    },
    {
      title: '客户编号',
      width: 180,
      dataIndex: 'custCode'
    },
    {
      title: '客户名称',
      width: 180,
      dataIndex: 'custName'
    },
    {
      title: '订单日期',
      width: 110,
      align: 'center',
      dataIndex: 'docTime'
    },
    {
      title: '客户联系人',
      width: 130,
      align: 'center',
      dataIndex: 'custContactName'
    },
    {
      title: '客户联系人电话',
      width: 120,
      align: 'center',
      dataIndex: 'custContactTel'
    },
    {
      title: '是否含税',
      width: 80,
      align: 'center',
      dataIndex: 'taxInclFlag',
      render: (text) => (text === '1' ? '是' : '否')
    },
    {
      title: '含税总金额',
      width: 100,
      align: 'right',
      dataIndex: 'amt'
    },
    {
      title: '应收款金额',
      width: 100,
      align: 'right',
      dataIndex: 'openAmt'
    },
    {
      title: '已支付金额',
      width: 100,
      align: 'right',
      dataIndex: 'payedAmt'
    },
    {
      title: '待收款金额',
      width: 100,
      align: 'right',
      dataIndex: 'apAmt'
    },
    {
      title: '本币币种',
      width: 80,
      align: 'center',
      dataIndex: 'homeCurrName'
    },
    {
      title: '币种',
      width: 80,
      align: 'center',
      dataIndex: 'currName'
    },
    {
      title: '汇率',
      width: 80,
      align: 'right',
      dataIndex: 'currRate'
    },
    {
      title: '支付时间',
      width: 150,
      align: 'center',
      dataIndex: 'payTime'
    },
    {
      title: '支付状态',
      width: 100,
      align: 'center',
      dataIndex: 'payStatusName'
    },
    {
      title: '备注',
      width: 120,
      dataIndex: 'remark'
    },
    {
      title: '工单接入异常信息',
      width: 240,
      align: 'left',
      dataIndex: 'errorMsg'
    }
  ];
};

// 列表页----订单明细(子列表)
const getOrderInfoColumns = (): Array<ElSearchTableColumns> => {
  return [
    {
      title: '行号',
      width: 60,
      align: 'left',
      dataIndex: 'lineNo',
      fixed: true
    },
    {
      title: '行类型',
      width: 100,
      align: 'center',
      dataIndex: 'lineTypeName'
    },
    {
      title: '行状态',
      width: 100,
      align: 'center',
      dataIndex: 'lineStatusName'
    },
    {
      title: '商品编号',
      width: 200,
      align: 'left',
      dataIndex: 'itemCode'
    },
    {
      title: '商品名称',
      width: 250,
      align: 'left',
      dataIndex: 'itemName'
    },
    {
      title: '数量',
      width: 90,
      align: 'right',
      dataIndex: 'qty'
    },
    {
      title: '单位',
      width: 90,
      dataIndex: 'uomName'
    },
    {
      title: '含税价格',
      width: 90,
      align: 'right',
      dataIndex: 'price'
    },
    {
      title: '应收款金额',
      width: 100,
      align: 'right',
      dataIndex: 'openAmt'
    },
    {
      title: '已收款金额',
      width: 100,
      align: 'right',
      dataIndex: 'payedAmt'
    },
    {
      title: '待收款金额',
      width: 100,
      align: 'right',
      dataIndex: 'apAmt'
    },
    {
      title: '支付状态',
      width: 90,
      align: 'center',
      dataIndex: 'payStatusName'
    },
    {
      title: '含税金额',
      width: 90,
      align: 'right',
      dataIndex: 'amt'
    },
    {
      title: '备注',
      width: 150,
      dataIndex: 'remark'
    }
  ];
};

export {
  getTableSearchFormItems,
  getTableActionButtons,
  getTableColumns,
  getOrderInfoColumns
};
